package com.chen.user.service;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chen.user.common.Result;
import com.chen.user.entity.Comment;
import com.chen.user.mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService {


    @Autowired
    private CommentMapper commentMapper;

    public List<Comment> getCommentPage(Integer roomId) {
        LambdaQueryWrapper<Comment> commentLambdaQueryWrapper = new LambdaQueryWrapper<>();
        commentLambdaQueryWrapper.eq(Comment::getRoomId, roomId);
        List<Comment> commentList = commentMapper.selectList(commentLambdaQueryWrapper);
        return commentList;

    }

    public Result addComment(Comment comment) {

        int count = commentMapper.addComment(comment);
        if (count == 0) {
            return Result.error("400", "添加失败");
        }

        return Result.success("添加成功");
    }
}
